<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- qextensionmanager.cpp -->
  <title>QExtensionManager Class | Qt Designer Manual</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.14</a></td><td ><a href="qtdesigner-manual.html">Qt Designer Manual</a></td><td ><a href="qtdesigner-module.html">C++ Classes</a></td><td >QExtensionManager</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtdesigner-manual.html">Qt 5.14.2 Reference Documentation</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#reimplemented-public-functions">Reimplemented Public Functions</a></li>
<li class="level1"><a href="#related-non-members">Related Non-Members</a></li>
<li class="level1"><a href="#macros">Macros</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QExtensionManager Class</h1>
<!-- $$$QExtensionManager-brief -->
<p>The QExtensionManager class provides extension management facilities for Qt Designer. <a href="#details">More...</a></p>
<!-- @@@QExtensionManager -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QExtensionManager&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += designer</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <a href="../qtcore/qobject.html">QObject</a> and <a href="qabstractextensionmanager.html">QAbstractExtensionManager</a></td></tr></table></div><ul>
<li><a href="qextensionmanager-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="public-functions"></a>
<h2 id="public-functions">Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qextensionmanager.html#QExtensionManager">QExtensionManager</a></b>(QObject *<i>parent</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qextensionmanager.html#dtor.QExtensionManager">~QExtensionManager</a></b>()</td></tr>
</table></div>
<a name="reimplemented-public-functions"></a>
<h2 id="reimplemented-public-functions">Reimplemented Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> virtual QObject *</td><td class="memItemRight bottomAlign"><b><a href="qextensionmanager.html#extension">extension</a></b>(QObject *<i>object</i>, const QString &amp;<i>iid</i>) const override</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qextensionmanager.html#registerExtensions">registerExtensions</a></b>(QAbstractExtensionFactory *<i>factory</i>, const QString &amp;<i>iid</i> = QString()) override</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qextensionmanager.html#unregisterExtensions">unregisterExtensions</a></b>(QAbstractExtensionFactory *<i>factory</i>, const QString &amp;<i>iid</i> = QString()) override</td></tr>
</table></div>
<a name="related-non-members"></a>
<h2 id="related-non-members">Related Non-Members</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> T </td><td class="memItemRight bottomAlign"><b><a href="qextensionmanager.html#qt_extension">qt_extension</a></b>(QAbstractExtensionManager *<i>manager</i>, QObject *<i>object</i>)</td></tr>
</table></div>
<a name="macros"></a>
<h2 id="macros">Macros</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qextensionmanager.html#Q_DECLARE_EXTENSION_INTERFACE">Q_DECLARE_EXTENSION_INTERFACE</a></b>(<i>ExtensionName</i>, <i>Identifier</i>)</td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QExtensionManager-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>In <i>Qt Designer</i> the extensions are not created until they are required. For that reason, when implementing an extension, you must also create a <a href="qextensionfactory.html">QExtensionFactory</a>, i.e a class that is able to make an instance of your extension, and register it using <i>Qt Designer</i>'s extension manager.</p>
<p>The registration of an extension factory is typically made in the <a href="qdesignercustomwidgetinterface.html#initialize">QDesignerCustomWidgetInterface::initialize</a>() function:</p>
<pre class="cpp">

          <span class="type">void</span> MyPlugin<span class="operator">::</span>initialize(<span class="type"><a href="qdesignerformeditorinterface.html">QDesignerFormEditorInterface</a></span> <span class="operator">*</span>formEditor)
          {
              <span class="keyword">if</span> (initialized)
                  <span class="keyword">return</span>;

              <span class="type"><a href="qextensionmanager.html#QExtensionManager">QExtensionManager</a></span> <span class="operator">*</span>manager <span class="operator">=</span> formEditor<span class="operator">-</span><span class="operator">&gt;</span>extensionManager();
              Q_ASSERT(manager <span class="operator">!</span><span class="operator">=</span> <span class="number">0</span>);

              manager<span class="operator">-</span><span class="operator">&gt;</span>registerExtensions(<span class="keyword">new</span> MyExtensionFactory(manager)<span class="operator">,</span>
                                          Q_TYPEID(<span class="type"><a href="qdesignertaskmenuextension.html">QDesignerTaskMenuExtension</a></span>));

              initialized <span class="operator">=</span> <span class="keyword">true</span>;
          }

</pre>
<p>The QExtensionManager is not intended to be instantiated directly. You can retrieve an interface to <i>Qt Designer</i>'s extension manager using the <a href="qdesignerformeditorinterface.html#extensionManager">QDesignerFormEditorInterface::extensionManager</a>() function. A pointer to <i>Qt Designer</i>'s current <a href="qdesignerformeditorinterface.html">QDesignerFormEditorInterface</a> object (<code>formEditor</code> in the example above) is provided by the <a href="qdesignercustomwidgetinterface.html#initialize">QDesignerCustomWidgetInterface::initialize</a>() function's parameter. When implementing a custom widget plugin, you must subclass the <a href="qdesignercustomwidgetinterface.html">QDesignerCustomWidgetInterface</a> to expose your plugin to <i>Qt Designer</i>.</p>
<p>Then, when an extension is required, <i>Qt Designer</i>'s extension manager will run through all its registered factories calling <a href="qextensionfactory.html#createExtension">QExtensionFactory::createExtension</a>() for each until the first one that is able to create the requested extension for the selected object, is found. This factory will then make an instance of the extension.</p>
<p>There are four available types of extensions in <i>Qt Designer</i>: <a href="qdesignercontainerextension.html">QDesignerContainerExtension</a> , <a href="qdesignermembersheetextension.html">QDesignerMemberSheetExtension</a>, <a href="qdesignerpropertysheetextension.html">QDesignerPropertySheetExtension</a> and <a href="qdesignertaskmenuextension.html">QDesignerTaskMenuExtension</a>. <i>Qt Designer</i>'s behavior is the same whether the requested extension is associated with a container, a member sheet, a property sheet or a task menu.</p>
<p>For a complete example using the QExtensionManager class, see the <a href="qtdesigner-taskmenuextension-example.html">Task Menu Extension example</a>. The example shows how to create a custom widget plugin for Qt Designer, and how to to use the <a href="qdesignertaskmenuextension.html">QDesignerTaskMenuExtension</a> class to add custom items to <i>Qt Designer</i>'s task menu.</p>
</div>
<p><b>See also </b><a href="qextensionfactory.html">QExtensionFactory</a> and <a href="qabstractextensionmanager.html">QAbstractExtensionManager</a>.</p>
<!-- @@@QExtensionManager -->
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QExtensionManager[overload1]$$$QExtensionManagerQObject* -->
<h3 class="fn" id="QExtensionManager"><a name="QExtensionManager"></a>QExtensionManager::<span class="name">QExtensionManager</span>(<span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *<i>parent</i> = nullptr)</h3>
<p>Constructs an extension manager with the given <i>parent</i>.</p>
<!-- @@@QExtensionManager -->
<!-- $$$~QExtensionManager[overload1]$$$~QExtensionManager -->
<h3 class="fn" id="dtor.QExtensionManager"><a name="dtor.QExtensionManager"></a><code>[virtual] </code>QExtensionManager::<span class="name">~QExtensionManager</span>()</h3>
<p>Destroys the extension manager</p>
<!-- @@@~QExtensionManager -->
<!-- $$$extension[overload1]$$$extensionQObject*constQString& -->
<h3 class="fn" id="extension"><a name="extension"></a><code>[override virtual] </code><span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *QExtensionManager::<span class="name">extension</span>(<span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *<i>object</i>, const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>iid</i>) const</h3>
<p>Reimplements: <a href="qabstractextensionmanager.html#extension">QAbstractExtensionManager::extension</a>(QObject *object, const QString &amp;iid) const.</p>
<p>Returns the extension specified by <i>iid</i>, for the given <i>object</i>.</p>
<!-- @@@extension -->
<!-- $$$registerExtensions[overload1]$$$registerExtensionsQAbstractExtensionFactory*constQString& -->
<h3 class="fn" id="registerExtensions"><a name="registerExtensions"></a><code>[override virtual] </code><span class="type">void</span> QExtensionManager::<span class="name">registerExtensions</span>(<span class="type"><a href="qabstractextensionfactory.html">QAbstractExtensionFactory</a></span> *<i>factory</i>, const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>iid</i> = QString())</h3>
<p>Reimplements: <a href="qabstractextensionmanager.html#registerExtensions">QAbstractExtensionManager::registerExtensions</a>(QAbstractExtensionFactory *factory, const QString &amp;iid).</p>
<p>Register the extension specified by the given <i>factory</i> and extension identifier <i>iid</i>.</p>
<!-- @@@registerExtensions -->
<!-- $$$unregisterExtensions[overload1]$$$unregisterExtensionsQAbstractExtensionFactory*constQString& -->
<h3 class="fn" id="unregisterExtensions"><a name="unregisterExtensions"></a><code>[override virtual] </code><span class="type">void</span> QExtensionManager::<span class="name">unregisterExtensions</span>(<span class="type"><a href="qabstractextensionfactory.html">QAbstractExtensionFactory</a></span> *<i>factory</i>, const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>iid</i> = QString())</h3>
<p>Reimplements: <a href="qabstractextensionmanager.html#unregisterExtensions">QAbstractExtensionManager::unregisterExtensions</a>(QAbstractExtensionFactory *factory, const QString &amp;iid).</p>
<p>Unregister the extension specified by the given <i>factory</i> and extension identifier <i>iid</i>.</p>
<!-- @@@unregisterExtensions -->
</div>
<div class="relnonmem">
<h2>Related Non-Members</h2>
<!-- $$$qt_extension[overload1]$$$qt_extensionQAbstractExtensionManager*QObject* -->
<h3 class="fn" id="qt_extension"><a name="qt_extension"></a><span class="type">T</span> <span class="name">qt_extension</span>(<span class="type"><a href="qabstractextensionmanager.html">QAbstractExtensionManager</a></span> *<i>manager</i>, <span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *<i>object</i>)</h3>
<p>Returns the extension of the given <i>object</i> cast to type T if the object is of type T (or of a subclass); otherwise returns 0. The extension is retrieved using the given extension <i>manager</i>.</p>
<pre class="cpp">

         <span class="type"><a href="qdesignerpropertysheetextension.html">QDesignerPropertySheetExtension</a></span> <span class="operator">*</span>propertySheet;
         <span class="type"><a href="qextensionmanager.html#QExtensionManager">QExtensionManager</a></span> manager <span class="operator">=</span> formEditor<span class="operator">-</span><span class="operator">&gt;</span>extensionManager();

         propertySheet <span class="operator">=</span> qt_extension<span class="operator">&lt;</span><span class="type"><a href="qdesignerpropertysheetextension.html">QDesignerPropertySheetExtension</a></span><span class="operator">*</span><span class="operator">&gt;</span>(manager<span class="operator">,</span> widget);

         <span class="keyword">if</span>(propertySheet) {<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>}

</pre>
<p>When implementing a custom widget plugin, a pointer to <i>Qt Designer</i>'s current <a href="qdesignerformeditorinterface.html">QDesignerFormEditorInterface</a> object (<code>formEditor</code>) is provided by the <a href="qdesignercustomwidgetinterface.html#initialize">QDesignerCustomWidgetInterface::initialize</a>() function's parameter.</p>
<p>If the widget in the example above doesn't have a defined <a href="qdesignerpropertysheetextension.html">QDesignerPropertySheetExtension</a>, <code>propertySheet</code> will be a null pointer.</p>
<!-- @@@qt_extension -->
</div>
<div class="macros">
<h2>Macro Documentation</h2>
<!-- $$$Q_DECLARE_EXTENSION_INTERFACE[overload1]$$$Q_DECLARE_EXTENSION_INTERFACE -->
<h3 class="fn" id="Q_DECLARE_EXTENSION_INTERFACE"><a name="Q_DECLARE_EXTENSION_INTERFACE"></a><span class="name">Q_DECLARE_EXTENSION_INTERFACE</span>(<i>ExtensionName</i>, <i>Identifier</i>)</h3>
<p>Associates the given <i>Identifier</i> (a string literal) to the extension class called <i>ExtensionName</i>. The <i>Identifier</i> must be unique. For example:</p>
<pre class="cpp">

     Q_DECLARE_EXTENSION_INTERFACE(MyExtension<span class="operator">,</span> <span class="string">&quot;com.mycompany.myproduct.myextension&quot;</span>)

</pre>
<p>Using the company and product names is a good way to ensure uniqueness of the identifier.</p>
<p>When implementing a custom extension class, you must use Q_DECLARE_EXTENSION_INTERFACE() to enable usage of the <a href="qextensionmanager.html#qt_extension">qt_extension</a>() function. The macro is normally located right after the class definition for <i>ExtensionName</i>, in the associated header file.</p>
<p><b>See also </b><a href="../qtcore/qtplugin.html#Q_DECLARE_INTERFACE">Q_DECLARE_INTERFACE</a>().</p>
<!-- @@@Q_DECLARE_EXTENSION_INTERFACE -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2020 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
